第一次在Centos上安装mysql遇到的一些问题。
第一步就遇到问题,安装mysql-server报错没有可用包。
【解决方法】
先要安装mysql
1 | # wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm |
之后再安装mysql-server
1 | # yum -y install mysql-server |
然后systemctl enable mysqld
设置mysql自启动
之后systemctl start mysqld
这时候出问题了,运行之后一直卡着没有反应,如下
1 | [root@localhost ~]# systemctl start mysqld |
systemctl status mysqld
查看mysql服务的状态如下
1 | [root@localhost sbin]# systemctl status mysqld |
看不出问题,查看mysql的日志终于找到问题vim /var/log/mysqld.log
1
2
3
4
5
62017-05-14 16:40:16 0 [Note] Binlog end
170514 16:40:16 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
170515 17:04:15 mysqld_safe Logging to '/var/log/mysqld.log'.
170515 17:04:15 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-05-15 17:04:18 0 [ERROR] /usr/sbin/mysqld: ambiguous option '--character-set=utf8' (character-set-client-handshake, character_sets_dir)
2017-05-15 17:04:18 0 [ERROR] Aborting
原来是my.cnf文件中设置默认字符编码我写成character-set=ut8
而centos7版本中应该设置为default-character-set=utf8
之后继续启动mysql仍然无法启动,查看日志如下1
2
3
4
5
6
7
8
9
10
11
12
13
142017-05-15 17:14:21 1195 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)
2017-05-15 17:14:21 1195 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
2017-05-15 17:14:21 1195 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2017-05-15 17:14:21 1195 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-05-15 17:14:21 1195 [Note] InnoDB: The InnoDB memory heap is disabled
2017-05-15 17:14:21 1195 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-05-15 17:14:21 1195 [Note] InnoDB: Memory barrier is not used
2017-05-15 17:14:21 1195 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-05-15 17:14:21 1195 [Note] InnoDB: Using Linux native AIO
2017-05-15 17:14:21 1195 [Note] InnoDB: Not using CPU crc32 instructions
2017-05-15 17:14:21 1195 [Note] InnoDB: Initializing buffer pool, size = 128.0M
170515 17:04:18 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
注意ERROR
Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.
【解决方法】
在运行初始化权限表的时候使用增加参数—datadir
mysql_install_db —user=mysql —datadir=/usr/local/mysql/var
百度后
安装完mysql server时,一般要执行这个脚本对数据库初始化。 运行这个脚本,会初始化mysql的data目录,并且创建那些系统表。
同样也会初始化系统表空间并且关联innodb表与数据结构。
更多的相关可以点击这里查看
之后启动服务依然卡住,回看前面执行命令之后的提示1
2Alternatively you can run:
/usr/bin/mysql_secure_installation
即执行MySQL安全配置向导mysql_secure_installation
安装完mysql-server 会提示可以运行mysql_secure_installation。运行mysql_secure_installation会执行几个设置:
a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效
执行之后systemctl restart mysqld
命令可以正常执行了
可以正常启动登录mysql